package hr.ctg.service.dao;

import hr.ctg.domain.model.Dogadjaj;
import hr.jpa.dao.GenericDAOImpl;

import java.util.List;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

@AutoCreate
@Name("dogadjajDAO")
public class DogadjajDAO extends GenericDAOImpl<Dogadjaj, Integer> {
	public List<Dogadjaj> findByIdMjesta(final Integer idMjesta) {
		return executeNamedQuery("Dogadjaj.findByIdMjesta", idMjesta);
	}

	public List<Dogadjaj> findByIdZupanije(final int idZupanije) {
		return executeNamedQuery("Dogadjaj.findByIdZupanije", idZupanije);
	}

	public List<Dogadjaj> findByIdOtoka(final int idOtoka) {
		return executeNamedQuery("Dogadjaj.findByIdOtoka", idOtoka);
	}

	public Long findCountByIdZupanije(final Integer idZupanije) {
		return (Long) entityManager.createNamedQuery(
				"Dogadjaj.findCountByIdZupanije").setParameter(1, idZupanije)
				.getSingleResult();
	}

	public Long findCountByIdOtoka(final Integer idOtoka) {
		return (Long) entityManager.createNamedQuery(
				"Dogadjaj.findCountByIdOtoka").setParameter(1, idOtoka)
				.getSingleResult();
	}

	public Long findCountByIdMjesta(final Integer idMjesta) {
		return (Long) entityManager.createNamedQuery(
				"Dogadjaj.findCountByIdMjesta").setParameter(1, idMjesta)
				.getSingleResult();
	}

	@SuppressWarnings("unchecked")
	public List<Dogadjaj> findByIdKorisnika(final Integer idKorisnika) {
		return entityManager.createNamedQuery("Dogadjaj.findByIdKorisnika")
				.setParameter(1, idKorisnika).getResultList();
	}

	@SuppressWarnings("unchecked")
	public List<Dogadjaj> findByCurrentDate() {
		return entityManager.createNamedQuery("Dogadjaj.findByCurrentDate")
				.getResultList();
	}

}
